package com.ping.common;

import com.jfinal.config.Constants;
import com.jfinal.config.Handlers;
import com.jfinal.config.Interceptors;
import com.jfinal.config.JFinalConfig;
import com.jfinal.config.Plugins;
import com.jfinal.config.Routes;
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
import com.jfinal.plugin.c3p0.C3p0Plugin;
import com.jfinal.render.ViewType;
import com.ping.controller.BrandController;
import com.ping.controller.ErrorController;
import com.ping.controller.MarketController;
import com.ping.controller.PingController;
import com.ping.controller.StoreController;
import com.ping.controller.UserController;
import com.ping.demo.JFinalDemoController;
import com.ping.interceptor.PinInterceptor;
import com.ping.model.Brand;
import com.ping.model.Discount;
import com.ping.model.Market;
import com.ping.model.Notify;
import com.ping.model.Ping;
import com.ping.model.Store;
import com.ping.model.User;

public class PingConfig extends JFinalConfig{

	@Override
	public void configConstant(Constants me) {
		// TODO 配置JFinal常量
		me.setDevMode(true);
	}

	@Override
	public void configHandler(Handlers me) {
		// TOD 配置Handler接管请求
	}

	@Override
	public void configInterceptor(Interceptors me) {
		// TODO 配置JFinal拦截器
		me.add(new PinInterceptor());
	}

	@Override
	public void configPlugin(Plugins me) {
		// TODO 配置JFinal插件
/*		C3p0Plugin c3p0 = new C3p0Plugin(
				getProperty("jdbcUrl"), 
				getProperty("user"), 
				getProperty("password").trim());*/
		C3p0Plugin c3p0 = new C3p0Plugin("ping");
		me.add(c3p0);
		
		ActiveRecordPlugin arp = new ActiveRecordPlugin(c3p0);
		arp.setShowSql(true);
		me.add(arp);
		arp.addMapping("monkey_brand", "uuid", Brand.class);
		arp.addMapping("monkey_discount", "uuid", Discount.class);
		arp.addMapping("monkey_market", "uuid", Market.class);
		arp.addMapping("monkey_notify", "uuid", Notify.class);
		arp.addMapping("monkey_ping", "uuid", Ping.class);
		arp.addMapping("monkey_user", "uuid", User.class);
		arp.addMapping("monkey_store", "uuid", Store.class);
	}

	@Override
	public void configRoute(Routes me) {
		// TODO 配置JFinal路由
		me.add("/demo", JFinalDemoController.class);
		me.add("/brand", BrandController.class);
		me.add("/user", UserController.class);
		me.add("/market", MarketController.class);
		me.add("/pin", PingController.class);
		me.add("/store", StoreController.class);
		me.add("/error", ErrorController.class);
	}

}
